import React, { useEffect, useRef, useState } from "react";
import { NavBar, Image, List } from "antd-mobile";
import { useNavigate, Route } from "react-router-dom";
import "./index.less";
import { getCurrentUserInfo } from "@/utils/authority";
import MyWorkList from "./list";
import { getWorkList } from "./service";

const MyWork: React.FC<any> = () => {
	const navigate = useNavigate();
	const userId = getCurrentUserInfo()?.data?.id;
	const [listTo, setListTo] = useState<any>([]);
	const [listAlready, setListAlready] = useState<any>([]);
	const [specialProjectList, setSpecialProjectList] = useState<any>([]);
	const [specialProjectListAlready, setSpecialProjectListAlready] = useState<any>([]);

	const getListDataTo = async () => {
		const params = {
			userId: userId,
			whetherHandle: 0,
		};
		try {
			const { data } = await getWorkList(params);
			setListTo(data?.service);
			setSpecialProjectList(data?.plan);
		} catch {}
	};
	const getListDataAlready = async () => {
		const params = {
			userId: userId,
			whetherHandle: 1,
		};
		try {
			const { data } = await getWorkList(params);
			setListAlready(data?.service);
			setSpecialProjectListAlready(data?.plan);
		} catch {}
	};
	useEffect(() => {
		getListDataTo();
		// getListDataAlready();
	}, []);
	return (
		<div className="myWork-content">
			<div className="header">
				<div>
					<NavBar onBack={() => navigate("/")}>
						<div className="commontitle">我的任务</div>
					</NavBar>
				</div>
			</div>
			<MyWorkList
				listTo={listTo}
				listAlready={listAlready}
				specialProjectList={specialProjectList}
				specialProjectListAlready={specialProjectListAlready}
			/>
		</div>
	);
};

export default MyWork;
